# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test08
# Description:  property函数
# Author:       ASUS
# Date:         2019/3/19
#-------------------------------------------------------------------------------


class Rectangle:
    def __init__(self):
        self.left = 0
        self.top = 0

    def setPosition(self,position):
        print("setPosition方法被调用")
        self.left,self.top = position             #序列赋值

    def getPosition(self):
        print("getPosition方法被调用")
        return self.left,self.top                 #返回元组类型

    def deletePosition(self):
        print("position属性已经被删除")
        self.left = 0
        self.top = 0
    #通过property函数将上面三个方法与position属性绑定，对position属性进行相关操作就会调用相关方法
    position = property(getPosition,setPosition,deletePosition)

r = Rectangle()
r.left = 10
r.top = 20
print('left','=',r.left)
print('top','=',r.top)
print('position','=',r.position)
r.position = 100,200
print('position','=',r.position)
del r.position
print(r.position)
r.position = 30,40
print('position','=',r.position)

